/*
* @Author: sc
* @Date:   2019-01-04 13:52:04
* @Last Modified by:   sc
* @Last Modified time: 2019-01-08 00:46:42
*/
'use strict';
const path 					= require('path');
const webpack               = require('webpack');
const HtmlWebpackPlugin 	= require('html-webpack-plugin');
const ExtractTextPlugin		= require('extract-text-webpack-plugin');
module.exports = {
	entry: './src/page/app.jsx',
	output: {
		path: path.resolve(__dirname, 'dist'),
		publicPath : '/dist/',
		filename: 'js/[name].js'
	},
	resolve : {
		alias : {
			component 	: path.resolve(__dirname, 'src/component'),
			page 		: path.resolve(__dirname, 'src/page'),
			util 		: path.resolve(__dirname, 'src/util')
		}
	},
	module: {
		rules: [
			{
				test: /\.jsx$/,
				exclude: /(node_modules)/,
				use: {
					loader: 'babel-loader',
					options: {
						// 自动根据环境来进行打包
						presets: ['env', 'react']
					}
				}
			},
			// css文件的处理
			{
		        test: /\.css$/,
		        use: ExtractTextPlugin.extract({
			        fallback: "style-loader", // 将 JS 字符串生成为 style 节点
			        use: "css-loader"
		        })
		    },
		    // sass文件的处理
		    {
	            test: /\.scss$/,
	            use: ExtractTextPlugin.extract({
	            	fallback: "style-loader",
	                use: [ "css-loader", "sass-loader"]
	            })
        	},
        	// 图片的配置
        	{
		        test: /\.(png|jpg|gif)$/,
		        use: [
		          {
		            loader: 'url-loader',
		            options: {
		              limit: 8192,
		              name : 'resource/[name].[ext]'
		            }
		          }
		        ]
		    },
		    //字体图标的配置
        	{
		        test: /\.(eot|svg|ttf|woff|woff2|otf)$/,
		        use: [
		          {
		            loader: 'url-loader',
		            options: {
		              limit: 8192,
		              name : 'resource/[name].[ext]'
		            }
		          }
		        ]
		    }
		]
	},
	plugins : [
		// 处理html文件
		new HtmlWebpackPlugin({
			template : './src/view/index.html',
			filename : 'view/index.html',			
		}),
		// 独立css文件
		new ExtractTextPlugin('css/[name].css')
	],
	devServer: {
		port : 8081
    },
};